package com.cn.bulu.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.bulu.pojo.Goods;
import com.cn.bulu.service.WorkerService;
import com.cn.bulu.utils.BuluResult;
import com.cn.bulu.utils.redis.JedisUtil;

@Controller
@RequestMapping("/worker")
public class WorkerController {
	@Resource
	private WorkerService workerService;

	// 工人版注册
	@RequestMapping("/register")
	@ResponseBody
	public BuluResult register(/*String phone, String password*/String account) {
		BuluResult buluResult = workerService.register(/*phone, password*/account);
		return buluResult;
	}

	// 判断工人手机号是否已经被注册
	@RequestMapping("/isPhone")
	@ResponseBody
	public BuluResult isPhone(String phone) {
		BuluResult buluResult = workerService.isPhone(phone);
		return buluResult;
	}

	// 工人完善信息
	@RequestMapping("/completeWorkerData")
	@ResponseBody
	public BuluResult completeWorkerData(Integer workerId, String name, String province, String city,
			String workerSpaces, String headImg, Integer workerAge) {
		BuluResult buluResult = workerService.completeWorkerData(workerId, name, province, city, workerSpaces, headImg,
				workerAge);
		return buluResult;
	}

	// 修改密码
	@RequestMapping("/updateWorkerPassword")
	@ResponseBody
	public BuluResult updateWorkerPassword(/*String phone, String password*/String account) {
		BuluResult buluResult = workerService.updateWorkerPassword(/*phone, password*/account);
		return buluResult;
	}

	// 登陆
	@RequestMapping("/login")
	@ResponseBody
	public BuluResult login(/*String phone, String password*/ String account, String imei, HttpServletRequest request) {
		BuluResult buluResult = workerService.login(/*phone, password*/account, imei, request);
		return buluResult;
	}

	// 修改头像
	@RequestMapping("/updateHeadImg")
	@ResponseBody
	public BuluResult updateHeadImg(HttpServletRequest request, String headImg) {
		BuluResult buluResult = workerService.updateHeadImg(request, headImg);
		return buluResult;
	}

	// 查询可接订单各个类型数量
	@RequestMapping("/selectKejieNumber")
	@ResponseBody
	public BuluResult selectKejieNumber(HttpServletRequest request) {
		BuluResult buluResult = workerService.selectKejieNumber(request);
		return buluResult;
	}

	// 查询可接订单(测量安装维修都行)
	@RequestMapping("/selectKejie")
	@ResponseBody
	public BuluResult selectKejie(HttpServletRequest request, Integer type) {
		System.out.println("我看看");
		BuluResult buluResult = workerService.selectKejie(request, type);
		return buluResult;
	}

	// 点击我要接单
	@RequestMapping("/Binding")
	@ResponseBody
	public BuluResult Binding(HttpServletRequest request, Integer indentId) {
		BuluResult buluResult = workerService.binging(request, indentId);
		return buluResult;
	}

	// 查询已接订单各个类型数量
	@RequestMapping("/selectYijie")
	@ResponseBody
	public BuluResult selectYijie(HttpServletRequest request) {
		BuluResult buluResult = workerService.selectYijie(request);
		return buluResult;
	}

	// 查询已接订单
	@RequestMapping("/YesBinding")
	@ResponseBody
	public BuluResult YesBinding(HttpServletRequest request, Integer type) {
		BuluResult buluResult = workerService.YesBinding(request, type);
		return buluResult;
	}

	// 查询我的钱包
	@RequestMapping("/selectWallet")
	@ResponseBody
	public BuluResult selectWallet(HttpServletRequest request) {
		BuluResult buluResult = workerService.selectWallet(request);
		return buluResult;
	}

	// 点击放弃订单扣除钱
	@RequestMapping("/updateWallet")
	@ResponseBody
	public BuluResult updateWallet(HttpServletRequest request, Integer indentId) {
		BuluResult buluResult = workerService.updateWallet(request, indentId);
		return buluResult;
	}

	// 点击放弃查询应扣钱
	@RequestMapping("/selectPenalties")
	@ResponseBody
	public BuluResult selectPenalties(HttpServletRequest request, Integer indentId) {
		BuluResult buluResult = workerService.selectPenalties(request, indentId);
		return buluResult;
	}

	// 点击出发
	@RequestMapping("/insertJingwei")
	@ResponseBody
	public BuluResult insertJingwei(Integer indentId, String jingdu, String weidu) {
		BuluResult buluResult = workerService.insertJingwei(indentId, jingdu, weidu);
		return buluResult;
	}

	// 查询已完成订单
	@RequestMapping("/selectYiwcheng")
	@ResponseBody
	public BuluResult selectYiwcheng(HttpServletRequest request, Integer type, Integer page) {
		BuluResult buluResult = workerService.selectYiwcheng(request, type, page);
		return buluResult;
	}

	// 根据订单号查询详情
	@RequestMapping("/selectXiangqing")
	@ResponseBody
	public BuluResult selectXiangqing(Integer indentId) {
		BuluResult buluResult = workerService.selectXiangqing(indentId);
		return buluResult;
	}

	// 测量完成填写信息 goods 配件字符串 布拍照位置字符串 纱拍照位置字符串
	// 查询安装房间和布纱安装位置
	@RequestMapping("/selectLBS")
	@ResponseBody
	public BuluResult selectLBS() {
		BuluResult buluResult = workerService.selectLBS();
		return buluResult;
	}

	// 工人提现明细
	@RequestMapping("/selectMingxi")
	@ResponseBody
	public BuluResult selectMingxi(HttpServletRequest request,Integer page) {
		BuluResult buluResult = workerService.selectMingxi(request,page);
		return buluResult;
	}

	// 查询工人身份信息和银行信息
	@RequestMapping("/updateXinxi")
	@ResponseBody
	public BuluResult updateXinxi(HttpServletRequest request, String idnumber, String boundBank, String bankNumber,
			String imgs) {
		BuluResult buluResult = workerService.updateXinxi(request, idnumber, boundBank, bankNumber, imgs);
		return buluResult;
	}

	// 工人提交测量信息界面
	@RequestMapping("/updateTijiao")
	@ResponseBody // bumushu:[{},{},{}]
	public BuluResult updateTijiao(Goods goods, String bumishu, String shamishu, String toumishu, String cimgs,
			String finishShade) {

		BuluResult buluResult = workerService.updateTijiao(goods, bumishu, shamishu, toumishu, cimgs, finishShade);
		return buluResult;
	}

	// 更改手机号
	@RequestMapping("/updatePhone")
	@ResponseBody
	public BuluResult updatePhone(HttpServletRequest request, /*String passwor*/String account) {
		BuluResult buluResult = workerService.updatePhone(request, account);
		return buluResult;
	}

	// 退出登录
	@RequestMapping("/Logout")
	@ResponseBody
	public BuluResult Logout(HttpServletRequest request) {
		String sessionID = request.getParameter("sign");
		JedisUtil.removeSessionID(sessionID, 7);
		BuluResult buluResult = new BuluResult();
		buluResult.setStatus(0);
		return buluResult;
	}

	// 请求头像
	@RequestMapping("/selectTouxiang")
	@ResponseBody
	public BuluResult selectTouxiang(String phone) {
		BuluResult buluResult = workerService.selectTouxiang(phone);
		return buluResult;
	}

	// 点击商品查询商品信息
	@RequestMapping("/selectGoodxinxi")
	@ResponseBody
	public BuluResult selectGoodxinxi(Integer goodsId) {
		BuluResult buluResult = workerService.selectGoodxinxi(goodsId);
		return buluResult;
	}

	// 测量填写信息查询布特殊图
	@RequestMapping("/selectTeshu")
	@ResponseBody
	public BuluResult selectTeshu() {
		BuluResult buluResult = workerService.selectTeshu();
		return buluResult;
	}

	// 查询广告
	@RequestMapping("/selectGuanggao")
	@ResponseBody
	public BuluResult selectGuanggao() {
		BuluResult buluResult = workerService.selectGuanggao();
		return buluResult;
	}

	// 意见反馈
	@RequestMapping("/insertWenti")
	@ResponseBody
	public BuluResult insertWenti(HttpServletRequest request, String problemCount, String imgs) {
		BuluResult buluResult = workerService.insertWenti(request, problemCount, imgs);
		return buluResult;
	}

	// 请求帘头图片
	@RequestMapping("/selectSheadheadImg")
	@ResponseBody
	public BuluResult selectSheadheadImg() {
		BuluResult buluResult = workerService.selectSheadheadImg();
		return buluResult;
	}

	// 根据sampleId查询宽高限制
	@RequestMapping("/selectXianzhi")
	@ResponseBody
	public BuluResult selectXianzhi(Integer sampleId) {
		BuluResult buluResult = workerService.selectXianzhi(sampleId);
		return buluResult;
	}

	// 给订单中添加商品
	@RequestMapping("/insertGoods")
	@ResponseBody
	public BuluResult insertGoods(Integer indentId, Goods goods) {
		BuluResult buluResult = workerService.insertGoods(indentId, goods);
		return buluResult;
	}

	// 删除订单中商品
	@RequestMapping("/deleteGoods")
	@ResponseBody
	public BuluResult deleteGoods(Integer goodsId) {
		BuluResult buluResult = workerService.deleteGoods(goodsId);
		return buluResult;
	}

	// 添加安装图片
	@RequestMapping("/insertATupian")
	@ResponseBody
	public BuluResult insertATupian(String specialImgs) {
		BuluResult buluResult = workerService.insertATupian(specialImgs);
		return buluResult;
	}

	// 添加维修图片
	@RequestMapping("/insertWTupian")
	@ResponseBody
	public BuluResult insertWTupian(Integer specialId, String imgs) {
		BuluResult buluResult = workerService.insertWTupian(specialId, imgs);
		return buluResult;
	}

	// 消息中心
	@RequestMapping("/selectMessage")
	@ResponseBody
	public BuluResult selectMessage(Integer page) {
		BuluResult buluResult = workerService.selectMessage(page);
		return buluResult;
	}

	// 更改手机号
	@RequestMapping("/updatePhone2")
	@ResponseBody
	public BuluResult updatePhone2(HttpServletRequest request, String phone) {
		BuluResult buluResult = workerService.updatePhone2(request, phone);
		return buluResult;
	}

	// 查询所有银行卡
	@RequestMapping("/selectBank")
	@ResponseBody
	public BuluResult selectBank(HttpServletRequest request) {
		BuluResult buluResult = workerService.selectBank(request);
		return buluResult;
	}

	// 添加银行卡
	@RequestMapping("/insertBank")
	@ResponseBody
	public BuluResult insertBank(HttpServletRequest request, String boundBank, String bankNumber) {
		BuluResult buluResult = workerService.insertBank(request, boundBank, bankNumber);
		return buluResult;
	}

	// 设为默认
	@RequestMapping("/updateBank")
	@ResponseBody
	public BuluResult updateBank(HttpServletRequest request, Integer bankCardId) {
		BuluResult buluResult = workerService.updateBank(request, bankCardId);
		return buluResult;
	}

	// 删除银行卡
	@RequestMapping("/deleteBank")
	@ResponseBody
	public BuluResult deleteBank(Integer bankCardId) {
		BuluResult buluResult = workerService.deleteBank(bankCardId);
		return buluResult;
	}

	// 查询版权信息
	@RequestMapping("/selectCopyright")
	@ResponseBody
	public BuluResult selectCopyright() {
		BuluResult buluResult = workerService.selectCopyright();
		return buluResult;
	}

	// 查询说明
	@RequestMapping("/selectAboutMe")
	@ResponseBody
	public BuluResult selectAboutMe() {
		BuluResult buluResult = workerService.selectAboutMe();
		return buluResult;
	}

	// 查询软件使用许可协议
	@RequestMapping("/selectVersionIntroduce")
	@ResponseBody
	public BuluResult selectVersionIntroduce() {
		BuluResult buluResult = workerService.selectVersionIntroduce();
		return buluResult;
	}

	// 查询平台服务协议
	@RequestMapping("/selectAgreement")
	@ResponseBody
	public BuluResult selectAgreement() {
		BuluResult buluResult = workerService.selectAgreement();
		return buluResult;
	}

	// 添加成品帘安装图片
	@RequestMapping("/insertInstallImgs")
	@ResponseBody
	public BuluResult insertInstallImgs(Integer goodsId, String installImgs) {
		BuluResult buluResult = workerService.insertInstallImgs(goodsId, installImgs);
		return buluResult;
	}

	// 验证码验证成功之后改变订单状态 并给工人钱包加钱
	@RequestMapping("/updateIndent")
	@ResponseBody
	public BuluResult updateIndent(HttpServletRequest request, Integer indentId) {
		BuluResult buluResult = workerService.updateIndent(request, indentId);
		return buluResult;
	}

	// 申请提现（银行卡）
	@RequestMapping("/submitWithdrawal")
	@ResponseBody
	public BuluResult submitWithdrawal(HttpServletRequest request, Double money, Integer bankCardId) {
		BuluResult buluResult = workerService.submitWithdrawal(request, money, bankCardId);
		return buluResult;
	}

	/**
	 * 工人支付宝提现 XGH
	 * 
	 * @param request
	 * @param money
	 *            转账金额
	 * @param zhifubao
	 *            到账的支付宝号
	 * @param name
	 *            支付宝账号对应的名字
	 * @param password
	 *            密码
	 * @param status
	 *            选择提现方式
	 * @return
	 */
	@RequestMapping("/alipyWithdrawal")
	public @ResponseBody BuluResult alipyWithdrawal(HttpServletRequest request, Double money, String zhifubao,
			String name, String /*password*/account, Integer status) {
		BuluResult buluResult = workerService.alipyWithdrawal(request, money, zhifubao, name, account, status);
		return buluResult;
	}

	/**
	 * 工人第一次提现进入的接口 XGH
	 * 
	 * @param request
	 * @param alipyCode
	 * @param idCard
	 * @param faceIDCard
	 * @param backIDCard
	 * @return
	 */
	@RequestMapping("/auditPresentation")
	public @ResponseBody BuluResult auditPresentation(HttpServletRequest request, String alipyCode, String IdCard,
			String faceIDCard, String backIDCard) {
		BuluResult buluResult = workerService.auditPresentation(request, alipyCode, IdCard, faceIDCard, backIDCard);
		return buluResult;
	}

	/**
	 * 工人实时充值 XGH
	 * 
	 * @param request
	 * @param money
	 * @param cashInter
	 * @return
	 */
	@RequestMapping("/submitRecharge")
	@ResponseBody
	public BuluResult submitRecharge(HttpServletRequest request, Double money, Integer cashInter) {
		BuluResult buluResult = workerService.submitRecarge(request, money, cashInter);
		return buluResult;
	}

	// 查询个人信息
	@RequestMapping("/selectWorker")
	@ResponseBody
	public BuluResult selectWorker(HttpServletRequest request) {
		BuluResult buluResult = workerService.selectWorker(request);
		return buluResult;
	}

	// 修改工作区域
	@RequestMapping("/updateWorkerSpaces")

	@ResponseBody
	public BuluResult updateWorkerSpaces(HttpServletRequest request, String workerSpaces) {
		BuluResult buluResult = workerService.updateWorkerSpaces(request, workerSpaces);
		return buluResult;
	}

	// 修改工作区域
	@RequestMapping("/updateWorkerAddress")

	@ResponseBody
	public BuluResult updateWorkerAddress(HttpServletRequest request, String province, String city, String area) {
		BuluResult buluResult = workerService.updateWorkerAddress(request, province, city, area);
		return buluResult;
	}

	// // 查询鹿客学院信息
	// @RequestMapping("/selectCollegeMsg")
	// @ResponseBody
	// public BuluResult selectCollegeMsg(HttpServletRequest request) {
	// BuluResult buluResult = workerService.selectCollegeMsg(request);
	// return buluResult;
	// }
}
